<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
</head>
<body>
    <button>点击获取段子</button>
    <button>点击获取英雄</button>
    <button>本地server</button>
    <!-- 
      接口1: http://api.xiaohigh.com/lol
      接口2: http://api.xiaohigh.com/duanzi

      接口3: http://127.0.0.1:8090/server
      接口4: http://127.0.0.1:8090/delay-server
    -->
    <script>

        let axios1 = axios.create({
            baseURL:'http://api.xiaohigh.com',
            timeout:1*1000
        })
        let axios2 = axios.create({
            baseURL:'http://127.0.0.1:8090',
            timeout:1*1000
        })
                let btn=document.querySelectorAll('button')

                btn[0].onclick = async ()=>{
                    try {
                        const response = await axios1({
                            url:'/duanzi'
                        })
                        console.log(response.data);
                    } catch (error) {
                        console.log(error.message);
                    }
                }
                btn[1].onclick = async ()=>{
                    try {
                        const response = await axios1({
                            url:'/lol'
                        })
                        console.log(response.data);
                    } catch (error) {
                        console.log(error.message);
                    }
                }
                btn[2].onclick = async ()=>{
                    try {
                        const response = await axios2({
                            url:'/server'
                        })
                        console.log(response.data);
                    } catch (error) {
                        console.log(error.message);
                    }
                }

    </script>
</body>
</html>